$(function(){
	var cookieProp=$("#searchCookieId").val();
	if(cookieProp==null||cookieProp==""){
		cookieProp="history";
	}
	$(".header div").on("click",function(){
		var search=$(".header_search input").val();
		if(search==""||search==null){
		}else{
			//插入cookie
			setCookie(cookieProp,search,1);
			$(".header_search").submit();
		}
	})
	
	$(".history").on("click","li",function(){
		var historyDb=$(this).html();
		$(".header_search input").val(historyDb);
		$(".header_search").submit();
	})

	function setCookie(cname, cvalue, exdays) {
		cvalue = encodeURI(cvalue);
		var getCookiesValue = getCookie(cname);
		if(getCookiesValue!=null && getCookiesValue!=""){
			cvalue = getCookiesValue+"-^$#%#"+cvalue;
		}
        var d = new Date();
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires="+d.toUTCString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
	}
	//获取cookie
	function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1);
            if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
        }
        return "";
  	}
	function todoit(){
		var cc = getCookie(cookieProp);
		cc=cc.split("-^$#%#");
		var strs= new Array(); //定义一数组 
		strs=cc; //字符分割 
		if(strs!==null&&strs!=""){
			for (i=strs.length-1;i>=0 ;i-- ) 
			{ 
				//if(i<strs.length-5){
				//	return false;
				//}
				var hisVal=decodeURI(decodeURI(strs[i]));
				var h=0;
				for(j=i-1;j>=0 ;j--){
					var hisValLater=decodeURI(decodeURI(strs[j]));
					if(hisVal==hisValLater){
						h=h+1;
					}
				}
				if(h==0){
					console.log(i+"/"+hisVal); //分割后的字符输出 
					$(".history").append("<li>"+hisVal+"</li>");
				}
			}
		}
	}
	
	todoit();
})
